const collectionList=[
  {
    id:1,
    title:'测试作品集1',
    detail:'这是一个测试的mock数据,测试作品集包括了两个测试商品'
  },
  {
    id:2,
    title:'测试作品集2',
    detail:'这是一个测试的mock数据,测试作品集包括了三个测试商品'
  },
]

const getCollection = (collectionID)=>{
  for (let i=0;i<collectionList.length;i++){
    if(collectionID===collectionList[i].id){
      return collectionList[i];
    }
  }
}

const itemList=[
  {
    id:1,
    collectionID:1,
    ownerID:1,
    name:'测试商品1',
    detail:'这是一个测试的mock数据,测试商品1,属于测试作品集1',
    likes:88,
    image:'https://gw.alipayobjects.com/zos/rmsportal/JiqGstEfoWAOHiTxclqi.png',
    evidence:{
      txHash:'0x00000000000000000000000000000000000000000001',
      fileHash:'0x0000000000000000000000000000000000000000000000000001',
      blockchain:'安权链',
    },
    sell:{
      price:100,
      endTime:new Date(),
      appointUser:"1@1.com"
    }
  },
  {
    id:2,
    collectionID:1,
    ownerID:2,
    name:'测试商品2',
    detail:'这是一个测试的mock数据,测试商品2，属于测试作品集1',
    likes:100,
    image:'https://img1.baidu.com/it/u=2496571732,442429806&fm=26&fmt=auto&gp=0.jpg',
    evidence:{
      txHash:'0x20000000000000000000000000000000000000000002',
      fileHash:'0x2000000000000000000000000000000000000000000000000002',
      blockchain:'安权链',
    }
  },
  {
    id:3,
    collectionID:2,
    ownerID:3,
    name:'测试商品2',
    detail:'这是一个测试的mock数据,测试商品3，属于测试作品集2',
    likes:100,
    image:'https://img1.baidu.com/it/u=2496571732,442429806&fm=26&fmt=auto&gp=0.jpg',
    evidence:{
      txHash:'0x30000000000000000000000000000000000000000003',
      fileHash:'0x3000000000000000000000000000000000000000000000000003',
      blockchain:'安权链',
    }
  },
]

const getItem = (itemID)=>{
  for (let i=0;i<itemList.length;i++){
    if(itemID===itemList[i].id){
      return itemList[i];
    }
  }
}

export default {
  'GET /api/getItem': (req,res)=>{
    const { itemID } = req.query;
    const item = getItem(parseInt(itemID))
    const collection = getCollection(item.collectionID)
    res.send({
      'item':item,
      'collection':collection,
      'success':true,
      'message':'',
    });
  },
};
